package cn.iocoder.yudao.module.train.dal.mysql.coursecancel;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.train.dal.dataobject.connectDTO.CourseCancelDTO;
import cn.iocoder.yudao.module.train.dal.dataobject.connectDTO.CourseClassesCommodityDTO;
import cn.iocoder.yudao.module.train.dal.dataobject.course.CourseDO;
import cn.iocoder.yudao.module.train.dal.dataobject.coursecancel.CourseCancelDO;
import cn.iocoder.yudao.module.train.dal.dataobject.courseclasses.CourseClassesDO;
import cn.iocoder.yudao.module.train.dal.dataobject.coursecommodity.CourseCommodityDO;
import cn.iocoder.yudao.module.train.dal.dataobject.student.StudentDO;
import cn.iocoder.yudao.module.train.dal.dataobject.teacher.TeacherDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.train.controller.admin.coursecancel.vo.*;

/**
 * 课程消课记录 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface CourseCancelMapper extends BaseMapperX<CourseCancelDO> {

//    default PageResult<CourseCancelDO> selectPage(CourseCancelPageReqVO reqVO) {
//        return selectPage(reqVO, new LambdaQueryWrapperX<CourseCancelDO>()
//                .eqIfPresent(CourseCancelDO::getStudentId, reqVO.getStudentId())
//                .eqIfPresent(CourseCancelDO::getCommodityId, reqVO.getCommodityId())
//                .eqIfPresent(CourseCancelDO::getClassesId, reqVO.getClassesId())
//                .betweenIfPresent(CourseCancelDO::getCancelTime, reqVO.getCancelTime())
//                .betweenIfPresent(CourseCancelDO::getTeachingTime, reqVO.getTeachingTime())
//                .eqIfPresent(CourseCancelDO::getRestDuration, reqVO.getRestDuration())
//                .betweenIfPresent(CourseCancelDO::getCreateTime, reqVO.getCreateTime())
//                .orderByDesc(CourseCancelDO::getId));
//    }
    default PageResult<CourseCancelDTO> selectPage(CourseCancelPageReqVO reqVO){
        Page<CourseCancelDTO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        MPJLambdaWrapper<CourseCancelDO> wrapper = new MPJLambdaWrapper<CourseCancelDO>()
                .selectAll(CourseCancelDO.class)
                .selectAs(CourseDO::getName,CourseCancelDTO::getCourseName)
                .select(CourseCommodityDO::getCommodityName)
                .select(TeacherDO::getTeacherName)
                .select(StudentDO::getStudentName)
                .select(CourseClassesDO::getClassNumber)
                .leftJoin(CourseClassesDO.class, CourseClassesDO::getId, CourseCancelDO::getClassesId)
                .leftJoin(CourseCommodityDO.class, CourseCommodityDO::getId, CourseClassesDO::getCommodityId)
                .leftJoin(CourseDO.class, CourseDO::getId, CourseCommodityDO::getCourseId)
                .leftJoin(TeacherDO.class, TeacherDO::getId, CourseCommodityDO::getTeacherId)
                .leftJoin(StudentDO.class, StudentDO::getId, CourseCancelDO::getStudentId)


                .likeIfExists(CourseDO::getName, reqVO.getCourseName())
                .likeIfExists(CourseCommodityDO::getCommodityName, reqVO.getCommodityName())
                .likeIfExists(TeacherDO::getTeacherName, reqVO.getTeacherName())
                .likeIfExists(StudentDO::getStudentName, reqVO.getStudentName())
                .likeIfExists(CourseClassesDO::getClassNumber, reqVO.getClassNumber());
        IPage<CourseCancelDTO> resultPage = selectJoinPage(page, CourseCancelDTO.class, wrapper);
        return new PageResult<>(resultPage.getRecords(), resultPage.getTotal());
    }

}
